﻿using System.IO;
using System.Reflection;
using System.Text;

namespace MediaAssistant.DAL
{
    public class ResourceHelper
    {
        public static void CopyEmbededResource(string resource, string destinationFilename)
        {
            var resourceStream = Assembly.GetCallingAssembly().GetManifestResourceStream(resource);
            if (resourceStream == null) return;
            var buffer = new byte[resourceStream.Length];
            resourceStream.Read(buffer, 0, buffer.Length);
            resourceStream.Close();
            var fileStream = File.Create(destinationFilename);
            fileStream.Write(buffer, 0, buffer.Length);
            fileStream.Close();
        }
        public static string ReadText(string resource)
        {
            var resourceStream = Assembly.GetCallingAssembly().GetManifestResourceStream(resource);
            var buffer = new byte[resourceStream.Length];
            resourceStream.Read(buffer, 0, buffer.Length);
            resourceStream.Close();
           
            var encoding=new UTF8Encoding();
            return encoding.GetString(buffer);

        }
    }
}
